<?php

/**
 * pno actions.
 *
 * @package    tinystockmis
 * @subpackage pno
 * @author     Linfeng Wu
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class pnoActions extends sfActions {
    public function executeIndex(sfWebRequest $request) {
        $this->mfg_pnos = Doctrine::getTable('MfgPno')
                ->createQuery('a')
                ->execute();
    }

    public function executeGetPnoList(sfWebRequest $request) {
        
        $this->pager = new sfDoctrinePager(
                "MfgPno",
                $request->getParameter("rows",sfConfig::get("app_max_vouchers_per_page", 10))
            );

        $q = Doctrine::getTable("MfgPno")->getMfgPnoQuery();
        $this->pager->setQuery($q);
        $this->pager->setPage($request->getParameter("page",1));
        $this->pager->init();

    }

    public function executeNew(sfWebRequest $request) {
        $this->form = new MfgPnoForm();
    }

    public function executeCreate(sfWebRequest $request) {
        $this->forward404Unless($request->isMethod(sfRequest::POST));

        $this->form = new MfgPnoForm();

        $this->processForm($request, $this->form);

        $this->setTemplate('new');
    }

    public function executeEdit(sfWebRequest $request) {
        $this->forward404Unless($mfg_pno = Doctrine::getTable('MfgPno')->find(array($request->getParameter('id'))), sprintf('Object mfg_pno does not exist (%s).', $request->getParameter('id')));
        $this->form = new MfgPnoForm($mfg_pno);
    }

    public function executeUpdate(sfWebRequest $request) {
        $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
        $this->forward404Unless($mfg_pno = Doctrine::getTable('MfgPno')->find(array($request->getParameter('id'))), sprintf('Object mfg_pno does not exist (%s).', $request->getParameter('id')));
        $this->form = new MfgPnoForm($mfg_pno);

        $this->processForm($request, $this->form);

        $this->setTemplate('edit');
    }

    public function executeDelete(sfWebRequest $request) {
        $request->checkCSRFProtection();

        $this->forward404Unless($mfg_pno = Doctrine::getTable('MfgPno')->find(array($request->getParameter('id'))), sprintf('Object mfg_pno does not exist (%s).', $request->getParameter('id')));
        $mfg_pno->delete();

        $this->redirect('pno/index');
    }

    protected function processForm(sfWebRequest $request, sfForm $form) {
        $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
        if ($form->isValid()) {
            $mfg_pno = $form->save();

            $this->redirect('pno/edit?id='.$mfg_pno->getId());
        }
    }
}
